#include "getFilePath.h"

#ifdef _WIN32 // Windowsƽ̨
std::string yumoz::GetFilePath::GetDynamicLibraryPath()
{
	HMODULE hModule = GetModuleHandle(NULL);
	char path[MAX_PATH];
	GetModuleFileName(hModule, path, MAX_PATH);
	std::string fullPath(path);
	size_t pos = fullPath.find_last_of("\\/");
	return fullPath.substr(0, pos);
}

std::string yumoz::GetFilePath::getModulePath()
{
	char szDir[2048] = { 0 };
	::GetModuleFileNameA(NULL, szDir, sizeof(szDir));

	std::string strResult = szDir;
	strResult = strResult.substr(0, strResult.find_last_of("\\"));
	return strResult;
}

#elif __linux__  // Linuxƽ̨
std::string yumoz::GetFilePath::GetDynamicLibraryPath()
{
	Dl_info dlInfo;
	dladdr((void*)GetDynamicLibraryPath, &dlInfo);
	char* path = realpath(dlInfo.dli_fname, NULL);
	std::string fullPath(path);
	free(path);
	size_t pos = fullPath.find_last_of("/");
	return fullPath.substr(0, pos);
}



#else

#error Unsupported platform

#endif




